import java.util.Arrays;
import java.util.Scanner;

public class Test {
    Scanner
    public static void main(String[] args) {
        String str = "hello nowcoder";
        int ret = str.lastIndexOf(' ');
        System.out.println(str.length() - ret -1);



    }
    /**
     * 字符串查找
     */
    public static void main6(String[] args) {
        String str = "abcdef";
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);//会取到str这个字符串的i下标的值
            System.out.println(ch);
        }


    }
    /**
     * 比较大小
     */
    public static void main4(String[] args) {
        String s1 = new String("wish");
        String s2 = new String("happy");
        String s3 = new String("Happy");
        System.out.println(s3.equalsIgnoreCase(s2));
        //int ret = s1.compareTo(s2);
        int ret = s2.compareToIgnoreCase(s3);
        if(ret>0){
            System.out.println("s1>s2");
        }else if(ret<0){
            System.out.println("s1<s2");
        }else{
            System.out.println("s1==s2");
        }
    }
    public static void main3(String[] args) {
        char[] ch = new char[]{'a', 'b', 'c'};
        String s1 = new String(ch); // s1对象并不在常量池中
        s1.intern(); // s1.intern()；调用之后，会将s1对象的引用放入到常量池中
        String s2 = "abc"; // "abc" 在常量池中存在了，s2创建时直接用常量池中"abc"的引用
        System.out.println(s1 == s2);
    }
    public static void main2(String[] args) {
        char[] ch = new char[]{'a', 'b', 'c'};
        String s1 = new String(ch); // s1对象并不在常量池中
        String s2 = "abc";
        System.out.println(s1 == s2);
    }

    public static void main1(String[] args) {

        String str1 = "abcd";
        String str2 = "abcd";
        String str3 = new String("abcd");
        String str4 = new String("abcd");
        if(str1 == str3){
            System.out.println("111");
        }
        System.out.println(str1 == str2);
        System.out.println(str3 == str4);
        System.out.println(str1 == str3);




       /* // 1. 使用常量串构造，【直接赋值字符串】，用的最多
        String str1 = "wish";
        System.out.println(str1.length());
        // 2. new一个String对象
        String str2 = new String("you");
        // 3.使用字符数组进行构造【把一个字符数组转变为一个字符串】
        char[] ch = {'h','a','p','p','y'};
        String str3 = new String(ch);
        System.out.println(str2);
        System.out.println(str3);*/
    }
}
